package jmine.tec.json;

import java.io.IOException;
import java.io.Writer;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;

/**
 * JSONNull. Implementado como enum com apenas 1 elemento para garantir unicidade, serializacao, etc
 * 
 * @author takeshi
 */
public enum JSONNullObject implements JSON {

    INSTANCE {

        /**
         * {@inheritDoc}
         */
        public Map<String, JSON> getAllProperties() {
            return Collections.emptyMap();
        }

        /**
         * {@inheritDoc}
         */
        public JSON getProperty(String propertyName) {
            return INSTANCE;
        }

        /**
         * {@inheritDoc}
         */
        public Collection<String> getPropertyNames() {
            return Collections.emptyList();
        }

        /**
         * {@inheritDoc}
         */
        public Collection<JSON> getPropertyValues() {
            return Collections.emptyList();
        }

        /**
         * {@inheritDoc}
         */
        public int getSize() {
            return 0;
        }

        /**
         * {@inheritDoc}
         */
        public void setProperty(String propertyName, JSON value) {
        }

        /**
         * {@inheritDoc}
         * 
         * @see java.lang.Enum#toString()
         */
        @Override
        public String toString() {
            return "null";
        }

        /**
         * {@inheritDoc}
         */
        public Writer write(Writer writer) throws IOException {
            return writer.append("null");
        }
    }

}
